using System;
using System.Drawing;
using System.Windows.Forms;

namespace ReflectionIT.UserSettings
{
	/// <summary>
	/// Summary description for FormSetting.
	/// </summary>
	[Serializable]
	public class FormSetting
	{
		private Point _location;
		private string _name;
		private Size _size;
		private FormWindowState _windowState;

		public FormSetting(string name)
		{
			this._name = name;
		}

		/// <summary>
		/// Get the name used for this FormSetting
		/// </summary>
		public string Name {
			get { return (this._name); }
		}

		/// <summary>
		/// Backup the Size, Location and WindowState (only when not Minimized)
		/// </summary>
		/// <param name="form"></param>
		public virtual void Backup(Form form) {
			if (form.WindowState != FormWindowState.Minimized) {
				// Only when not Maximized
				if (form.WindowState != FormWindowState.Maximized) {
					this._location = form.Location;
					this._size = form.Size;
				}
				this._windowState = form.WindowState;
			}
		}

		/// <summary>
		/// Eventhandler 
		/// </summary>
		/// <param name="sender">Form which is Moved or Resized</param>
		/// <param name="e"></param>
		public virtual void FormMovedOrResized(object sender, EventArgs e) {
			Backup((Form)sender);
		}

		/// <summary>
		/// Restore the Size, Location and WindowState for the given form
		/// </summary>
		/// <param name="form"></param>
		public virtual void Restore(Form form) {
			form.Location = this._location;
			form.Size = this._size;
			form.WindowState = this._windowState;
		}
	}
}
